#!/bin/bash

PACKAGE=SocketDemo

SDIR=$(cd "$(dirname "${BASE_SOURCE[0]}")" && pwd)
JDIR=${SDIR}/${PACKAGE}

CCB_JDK=/usr/CCB/ECP/JRE
JAVA=/usr/bin/java
JAVAC=/usr/bin/javac
if [ -x "${CCB_JDK}/bin/java" ] && [ -x "${CCB_JDK}/bin/javac" ]; then
    JAVA=${CCB_JDK}/bin/java
    JAVAC=${CCB_JDK}/bin/javac
fi

if [ ! -x "${JAVA}" ] || [ ! -x "${JAVAC}" ]; then
    echo "Cannot find Java Environment"
    exit 1
fi

# Build
echo "Building ..."
eval ${JAVAC} "${JDIR}/*.java"

# Run
pushd "${SDIR}" > /dev/null || exit $?
echo "Running ..."
eval ${JAVA} "${PACKAGE}.App $*"
popd > /dev/null || exit $?
